package company.tools.editor;

import org.iweb.html.impl.basic.Div
import org.iweb.html.impl.basic.Head
import org.iweb.html.impl.basic.Html
import org.iweb.html.impl.basic.Script
import org.iweb.html.impl.basic.Head.DefaultScript
import org.iweb.html.impl.basic.Head.DefaultStyle
import org.iweb.html.impl.basic.Head.Meta
import org.iweb.web.ui.layout.Layout;


@Layout(name="ace-layout")
class AceLayout{

	@Override
	public Object render(String context,String page) {
		
		//String context="/iweb";
		
		Meta m=new Meta();
		m.addAttr("name", "viewport");
		m.addAttr("content", "width=device-width, initial-scale=1.0");
		
		getHtml().getHead().append(m);// DefaultScript("/static/js/jquery-1.9.1.js"));
		
		getHtml().getHead().addStyleFile(context+"/template/static/css/bootstrap.css");
		getHtml().getHead().addStyleFile(context+"/template/static/css/bootstrap-responsive.css");
		
		DefaultStyle less=new DefaultStyle();
		less.addAttr("rel","stylesheet/less");
		less.addAttr("href",context+"/template/static/css/style.less");
		
		getHtml().getHead().append(less);
		
		Div pageContainer=new Div();
		pageContainer.setId("page-container");
		pageContainer.setClassStyle("container-fluid");
		
		Div loading=new Div();
		loading.setId("loading");
		
		pageContainer.append(loading);
		
		
		
		getHtml().getBody().append(pageContainer);
		
		getHtml().getBody().append(new DefaultScript(context+"/template/static/js/jquery-1.10.1.js"));
		getHtml().getBody().append(new DefaultScript(context+"/template/static/js/jquery-migrate-1.2.1.js"));
		getHtml().getBody().append(new DefaultScript(context+"/template/static/js/less-1.3.3.min.js"));
		getHtml().getBody().append(new DefaultScript(context+"/template/static/js/bootstrap.js"));		
		
		getHtml().getBody().append(new DefaultScript(context+"/template/static/js/ace/ace.js"));
		getHtml().getBody().append(new DefaultScript(context+"/template/static/js/ace/ext-language_tools.js"));
		
		getHtml().getBody().append(new Script().setText(" var pageName='"+context+"/portal"+page+"'"));
		
		getHtml().getBody().append(new DefaultScript(context+"/template/static/js/internal.js"));
		
		//getHtml().getBody().append(new Script().setText("ace.require('ace/ext/language_tools'); var aceEditor = ace.edit('editor');aceEditor.setTheme('ace/theme/eclipse');aceEditor.getSession().setMode('ace/mode/groovy');aceEditor.setOptions({enableBasicAutocompletion: true,enableSnippets: true});"));
		
		
		return getHtml();
		
	}
	
	private Html html;
	
		public Object renderInt(){
			Object res=render();
			if(res==null){
				res="Pagina di Test";
			}
			return res;
		}
	
		public Html getHtml() {
			if(html==null)
				html=new Html("");
			return html;
		}
	
		public void setHtml(Html html) {
			this.html = html;
		}
		

}